import request from '@/utils/request'

/** 角色API开始 */

export function addSysRole(data) {
  return request({
    url: '/api/admin/sysrole/addSysRole',
    method: 'post',
    needLoading: true,
    data
  })
}

export function updateSysRole(data) {
  return request({
    url: '/api/admin/sysrole/updateSysRole',
    method: 'put',
    needLoading: true,
    data
  })
}

export function queryRoleName() {
  return request({
    url: '/api/admin/sysrole/queryRoleName',
    method: 'get'
  })
}

export function querySysMenuTree() {
  return request({
    url: '/api/admin/sysmenu/querySysMenuTree',
    method: 'get'
  })
}

export function queryMenuIdByRoleId(query) {
  return request({
    url: '/api/admin/sysmenu/queryMenuIdByRoleId',
    method: 'get',
    params: query
  })
}

export function authorizeMenuToRole(data) {
  return request({
    url: '/api/admin/sysmenu/authorizeMenuToRole',
    method: 'post',
    needLoading: true,
    headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' },
    data
  })
}
export function querySysMenuButtonTree() {
  return request({
    url: '/api/admin/sysmenu/querySysMenuButtonTree',
    method: 'get'
  })
}
export function queryMenuButtonByRoleCode(data) {
  return request({
    url: '/api/admin/sysmenu/queryMenuButtonByRoleCode',
    method: 'get',
    params: {
      roleCode: data
    }
  })
}
export function authorizeMenuButtonToRole(data) {
  return request({
    url: '/api/admin/sysmenu/authorizeMenuButtonToRole',
    method: 'post',
    needLoading: true,
    data
  })
}
export function authorizeRoleToUser(data) {
  return request({
    url: '/api/admin/sysuser/authorizeRoleToUser',
    method: 'post',
    data
  })
}
export function authorizeUserToRole(data) {
  return request({
    url: '/api/admin/sysrole/authorizeUserToRole',
    method: 'post',
    data
  })
}

/** 角色API结束 */

/** 接口权限API开始 */
export function querySysUrl(query) {
  return request({
    url: '/api/admin/sysurl/querySysUrl',
    method: 'get',
    params: query
  })
}

export function addSysUrl(data) {
  return request({
    url: '/api/admin/sysurl/addSysUrl',
    method: 'post',
    needLoading: true,
    data
  })
}

export function updateSysUrl(data) {
  return request({
    url: '/api/admin/sysurl/updateSysUrl',
    method: 'put',
    needLoading: true,
    data
  })
}

export function queryRoleIdByUrlId(query) {
  return request({
    url: '/api/admin/sysurl/queryRoleIdByUrlId',
    method: 'get',
    params: query
  })
}

export function authorizeRoleToUrl(data) {
  return request({
    url: '/api/admin/sysurl/authorizeRoleToUrl',
    method: 'post',
    needLoading: true,
    headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' },
    data
  })
}
/** 接口权限API结束 */

/** 数据权限API开始 */
export function queryRoleCode(data) {
  return request({
    url: '/api/admin/sysrole/queryRoleCode',
    method: 'get'
  })
}

export function queryDataFieldByMenuCode(data) {
  return request({
    url: '/api/admin/sysmenu/queryDataFieldByMenuCode',
    method: 'get',
    params: {
      menuCode: data
    }
  })
}
export function deleteDataField(data) {
  return request({
    url: '/api/admin/sysmenu/deleteDataField',
    method: 'post',
    needLoading: true,
    data
  })
}
export function authorizeMenuDataToRole(data) {
  return request({
    url: '/api/admin/sysmenu/authorizeMenuDataToRole',
    method: 'post',
    needLoading: true,
    data
  })
}

/** 数据权限API结束 */
